package interview;

public class lc88 {
    public static void main(String[] args) {
        merge(new int[]{1,2,3,0,0,0}, 3, new int[]{2,5,6}, 3);
    }
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] ans = nums1.clone();
        int t = 0;
        int i = 0, j = 0;
        while(i < m && j < n){
            if(nums1[i] < nums2[j]){
                ans[t++] = nums1[i++];
            }
            else{
                ans[t++] = nums2[j++];
            }
        }
        if(i < m){
            for(int k = i; k < m; k++){
                ans[t++] = nums1[k];
            }
        }
        if(j < n){
            for(int k = j; k < n; k++){
                ans[t++] = nums2[k];
            }
        }
        for(int tt : ans)
            System.out.print(tt + " ");
        nums1 = ans;

    }
}
